package com.huilai.platform.country_platform.repository;

import com.huilai.platform.country_platform.model.AttractionsBuilding;
import com.huilai.platform.country_platform.model.PartyActivities;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;

/**
 * 作者：洪霓
 * 日期：2023/2/18
 * 注释：
 */
@Repository
public interface AttractionsBuildingReposity extends  JpaRepository<AttractionsBuilding, Integer>,JpaSpecificationExecutor<AttractionsBuilding>{
    @Modifying(clearAutomatically = true)
    @Transactional
    @Query(value = "insert into attractions_building(name, address, `describe`, image)" +
            "values(:#{#attractionsBuilding.name},:#{#attractionsBuilding.address},:#{#attractionsBuilding.describe},:#{#attractionsBuilding.image})", nativeQuery = true)
    Integer addBuilding(AttractionsBuilding attractionsBuilding);


    @Modifying(clearAutomatically = true)
    @Transactional
    @Query(value = "update attractions_building ab set ab.name = :#{#attractionsBuilding.name}, " +
            "ab.address = :#{#attractionsBuilding.address}, " +
            "ab.describe = :#{#attractionsBuilding.describe}, " +
            "ab.image = :#{#attractionsBuilding.image} where ab.building_id = :#{#attractionsBuilding.id}",nativeQuery = true)
    Integer updateBuilding(AttractionsBuilding attractionsBuilding);

    @Modifying(clearAutomatically = true)
    @Transactional
    @Query("delete from AttractionsBuilding ab where ab.id = :id")
    Integer deleteBuildingById(Integer id);

}
